﻿using CardGameCore.Common;

namespace CardGameCore.Battle
{
    public class SelectCardJudge : ISelectCardJudge
    {
        private readonly IBattlefield _battlefield;
        public SelectCardJudge(IBattlefield battlefield)
        {
            _battlefield = battlefield;
        }

        public bool TryAddBattleCard(Actor actor, Card card, out Vector2Int position)
        {
            position = Vector2Int.Zero;
            foreach (var vector2 in actor.Positions)
            {
                if (!TryAddBattleCard(actor, card, vector2)) continue;
                
                position = vector2;
                return true;
            }

            return false;
        }

        public bool TryAddBattleCard(Actor actor, Card card, Vector2Int position)
        {
            if (card.Cost + actor.BattleCost > _battlefield.MaxCost) return false;
            
            return !actor.BattleCards.ContainsKey(position);
        }
    }
}